package com.example.demo.controller;

import com.example.demo.bean.Student;

import com.example.demo.model.Person;
import com.example.demo.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
@RestController
public class StudentController {

    @Autowired
    private PersonService personService;

    @ResponseBody
    @RequestMapping(value = "/add", produces = {"application/json;charset=UTF-8"})
    public int  listStudent(Person person) {

        return personService.addUser(person);
    }

    @RequestMapping(value = "/find",method = RequestMethod.GET)
    public Person  findeStudent(@RequestParam(value = "id") int id) {
        return personService.findUser(id);
    }

   @RequestMapping(value = "/del",method = RequestMethod.GET)
    public int delStudent(@RequestParam(value = "id") int id) {
        return personService.delUser(id);
    }

    @RequestMapping(value = "/all",method = RequestMethod.GET)
    public Object allUsers() {
        HashMap<String,Object> h = new HashMap<>();
        h.put("data",personService.findAllUser());
        h.put("code","0001");
        h.put("status","success");
        return h;
    }



}
